﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Home/Home.Master" Inherits="System.Web.Mvc.ViewPage<IBupro.Models.SearchDiplomProject>" %>
<%@ Import Namespace="IBupro.Extensions" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HomeTitleContent" runat="server">
	<%: Html.Translate("applicationTitle") %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HomeContent" runat="server">


    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>
    
    
    
    <%:Html.TextBoxFor(model => model.SearchQuery, new { @class = "autocomplete" })%>

    <%:Html.DropDownList("projectType",Model.GetDiplomProjectTypeList())%>

    <input type="submit" value="Search" />
    <% } %>

    

     <script type="text/javascript">

         $(function () {
             $(".autocomplete").autocomplete({
                 source: function (request, response) {
                     $.getJSON("/Tag/List", {
                         term: extractLast(request.term)
                     }, response);
                 },
                 search: function () {
                     // custom minLength
                     var term = extractLast(this.value);
                     if (term.length < 1) {
                         return false;
                     }
                 },
                 focus: function () {
                     // prevent value inserted on focus
                     return false;
                 },
                 select: function (event, ui) {
                     var terms = split(this.value);
                     // remove the current input
                     terms.pop();
                     // add the selected item
                     terms.push(ui.item.value);
                     // add placeholder to get the comma-and-space at the end
                     terms.push("");
                     this.value = terms.join(", ");
                     return false;
                 },
                 selectFirst: function () {
                     // prevent value inserted on focus
                     return true;
                 },
                 change: function (event, ui) {
                     //if the value of the textbox does not match a suggestion, clear its value
                     if ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0) {
                         $(this).val('');
                     }
                 }
             }).live('keydown', function (e) {
                 var keyCode = e.keyCode || e.which;
                 //if TAB or RETURN is pressed and the text in the textbox does not match a suggestion, set the value of the textbox to the text of the first suggestion
                 if ((keyCode == 9 || keyCode == 13) && ($(".ui-autocomplete li:textEquals('" + $(this).val() + "')").size() == 0)) {
                     $(this).val($(".ui-autocomplete li:visible:first").text());
                 }


             });
             function split(val) {
                 return val.split(/,\s*/);
             }
             function extractLast(term) {
                 return split(term).pop();
             }
         });
    </script>

    <%Html.RenderAction("SearchByTags", "Home", new { query = Model.SearchQuery }); %>


</asp:Content>
